package com.guw.TestThread;

//Join合并线程,类似插队,此线程执行完成之后,再执行其它线程,其它线程阻塞
public class TestJoin implements Runnable{
    @Override
    public void run() {
        for (int i = 0; i <= 100 ; i++) {
            System.out.println(Thread.currentThread().getName()+"线程来了"+i);
        }
    }

    public static void main(String[] args) {
        TestJoin testJoin = new TestJoin();
        Thread thread1 = new Thread(testJoin,"VIP");
        Thread thread2 = new Thread(testJoin,"A");
        thread2.start();
        thread1.start();

        for (int i = 0; i <= 100 ; i++) {
            System.out.println("main线程启动了" + i);
            try {
                //插队,1和2相互并未插队?
                thread1.join();
                thread2.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        }


    }
}
